package com.hspedu.encap;

/**
 * @author 谷其昊
 * @version 1.0
 * @date 2022/1/20
 * @time 18:40
 */
public class Account {
    private String name;
    private double balance;
    private String password;

    public Account() {
    }

    public Account(String name, double balance, String password) {
        setName(name);
        setBalance(balance);
        setPassword(password);
    }

    public void setName(String name) {
        if (name.length() == 2 || name.length() == 3 || name.length() == 4) {
            this.name = name;
        } else {
            System.out.println("输入的姓名非法");
            this.name = "张三";
        }
    }

    public String getName() {
        return this.name;
    }

    public void setBalance(double balance) {
        if (balance < 20) {
            System.out.println("余额不能小于20");
            this.balance = 20;
        } else {
            this.balance = balance;
        }
    }

    public double getBalance() {
        return this.balance;
    }

    public void setPassword(String password) {
        if (password.length() == 6) {
            this.password = password;
        } else {
            System.out.println("密码输入不合法，已经初始化为 123456");
            this.password = "123456";
        }
    }

    public String getPassword() {
        return this.password;
    }

    public void getInfo() {
        System.out.println(name + " " + balance + " " + password);
    }

}

class AccountTest {
    public static void main(String[] args) {
        Account account = new Account("1", 19, "123");
        account.getInfo();
    }
}
